home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume8 / libhoward / part02 < prev    next >
Encoding:
Text File  |  1989-09-30  |  45.5 KB  |  1,477 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v08i080: libhoward portability library, part 2 of 9
  3. from: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  4. Reply-To: howard@dahlbeck.ericsson.se (Howard Gayle)
  5.  
  6. Posting-number: Volume 8, Issue 80
  7. Submitted-by: howard@dahlbeck.ericsson.se (Howard Gayle)
  8. Archive-name: libhoward/part02
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # If this archive is complete, you will see the following message at the end:
  17. #        "End of archive 2 (of 9)."
  18. # Contents:  LICENSE a2.3 a2d.c a2smp.c new-b.b
  19. # Wrapped by howard@hasse on Mon Sep 25 07:08:05 1989
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'LICENSE' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'LICENSE'\"
  23. else
  24. echo shar: Extracting \"'LICENSE'\" \(12487 characters\)
  25. sed "s/^X//" >'LICENSE' <<'END_OF_FILE'
  26. X            GNU GENERAL PUBLIC LICENSE
  27. X             Version 1, February 1989
  28. X
  29. X Copyright (C) 1989 Free Software Foundation, Inc.
  30. X                    675 Mass Ave, Cambridge, MA 02139, USA
  31. X Everyone is permitted to copy and distribute verbatim copies
  32. X of this license document, but changing it is not allowed.
  33. X
  34. X                Preamble
  35. X
  36. X  The license agreements of most software companies try to keep users
  37. Xat the mercy of those companies.  By contrast, our General Public
  38. XLicense is intended to guarantee your freedom to share and change free
  39. Xsoftware--to make sure the software is free for all its users.  The
  40. XGeneral Public License applies to the Free Software Foundation's
  41. Xsoftware and to any other program whose authors commit to using it.
  42. XYou can use it for your programs, too.
  43. X
  44. X  When we speak of free software, we are referring to freedom, not
  45. Xprice.  Specifically, the General Public License is designed to make
  46. Xsure that you have the freedom to give away or sell copies of free
  47. Xsoftware, that you receive source code or can get it if you want it,
  48. Xthat you can change the software or use pieces of it in new free
  49. Xprograms; and that you know you can do these things.
  50. X
  51. X  To protect your rights, we need to make restrictions that forbid
  52. Xanyone to deny you these rights or to ask you to surrender the rights.
  53. XThese restrictions translate to certain responsibilities for you if you
  54. Xdistribute copies of the software, or if you modify it.
  55. X
  56. X  For example, if you distribute copies of a such a program, whether
  57. Xgratis or for a fee, you must give the recipients all the rights that
  58. Xyou have.  You must make sure that they, too, receive or can get the
  59. Xsource code.  And you must tell them their rights.
  60. X
  61. X  We protect your rights with two steps: (1) copyright the software, and
  62. X(2) offer you this license which gives you legal permission to copy,
  63. Xdistribute and/or modify the software.
  64. X
  65. X  Also, for each author's protection and ours, we want to make certain
  66. Xthat everyone understands that there is no warranty for this free
  67. Xsoftware.  If the software is modified by someone else and passed on, we
  68. Xwant its recipients to know that what they have is not the original, so
  69. Xthat any problems introduced by others will not reflect on the original
  70. Xauthors' reputations.
  71. X
  72. X  The precise terms and conditions for copying, distribution and
  73. Xmodification follow.
  74. X
  75. X            GNU GENERAL PUBLIC LICENSE
  76. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  77. X
  78. X  0. This License Agreement applies to any program or other work which
  79. Xcontains a notice placed by the copyright holder saying it may be
  80. Xdistributed under the terms of this General Public License.  The
  81. X"Program", below, refers to any such program or work, and a "work based
  82. Xon the Program" means either the Program or any work containing the
  83. XProgram or a portion of it, either verbatim or with modifications.  Each
  84. Xlicensee is addressed as "you".
  85. X
  86. X  1. You may copy and distribute verbatim copies of the Program's source
  87. Xcode as you receive it, in any medium, provided that you conspicuously and
  88. Xappropriately publish on each copy an appropriate copyright notice and
  89. Xdisclaimer of warranty; keep intact all the notices that refer to this
  90. XGeneral Public License and to the absence of any warranty; and give any
  91. Xother recipients of the Program a copy of this General Public License
  92. Xalong with the Program.  You may charge a fee for the physical act of
  93. Xtransferring a copy.
  94. X
  95. X  2. You may modify your copy or copies of the Program or any portion of
  96. Xit, and copy and distribute such modifications under the terms of Paragraph
  97. X1 above, provided that you also do the following:
  98. X
  99. X    a) cause the modified files to carry prominent notices stating that
  100. X    you changed the files and the date of any change; and
  101. X
  102. X    b) cause the whole of any work that you distribute or publish, that
  103. X    in whole or in part contains the Program or any part thereof, either
  104. X    with or without modifications, to be licensed at no charge to all
  105. X    third parties under the terms of this General Public License (except
  106. X    that you may choose to grant warranty protection to some or all
  107. X    third parties, at your option).
  108. X
  109. X    c) If the modified program normally reads commands interactively when
  110. X    run, you must cause it, when started running for such interactive use
  111. X    in the simplest and most usual way, to print or display an
  112. X    announcement including an appropriate copyright notice and a notice
  113. X    that there is no warranty (or else, saying that you provide a
  114. X    warranty) and that users may redistribute the program under these
  115. X    conditions, and telling the user how to view a copy of this General
  116. X    Public License.
  117. X
  118. X    d) You may charge a fee for the physical act of transferring a
  119. X    copy, and you may at your option offer warranty protection in
  120. X    exchange for a fee.
  121. X
  122. XMere aggregation of another independent work with the Program (or its
  123. Xderivative) on a volume of a storage or distribution medium does not bring
  124. Xthe other work under the scope of these terms.
  125. X
  126. X  3. You may copy and distribute the Program (or a portion or derivative of
  127. Xit, under Paragraph 2) in object code or executable form under the terms of
  128. XParagraphs 1 and 2 above provided that you also do one of the following:
  129. X
  130. X    a) accompany it with the complete corresponding machine-readable
  131. X    source code, which must be distributed under the terms of
  132. X    Paragraphs 1 and 2 above; or,
  133. X
  134. X    b) accompany it with a written offer, valid for at least three
  135. X    years, to give any third party free (except for a nominal charge
  136. X    for the cost of distribution) a complete machine-readable copy of the
  137. X    corresponding source code, to be distributed under the terms of
  138. X    Paragraphs 1 and 2 above; or,
  139. X
  140. X    c) accompany it with the information you received as to where the
  141. X    corresponding source code may be obtained.  (This alternative is
  142. X    allowed only for noncommercial distribution and only if you
  143. X    received the program in object code or executable form alone.)
  144. X
  145. XSource code for a work means the preferred form of the work for making
  146. Xmodifications to it.  For an executable file, complete source code means
  147. Xall the source code for all modules it contains; but, as a special
  148. Xexception, it need not include source code for modules which are standard
  149. Xlibraries that accompany the operating system on which the executable
  150. Xfile runs, or for standard header files or definitions files that
  151. Xaccompany that operating system.
  152. X
  153. X  4. You may not copy, modify, sublicense, distribute or transfer the
  154. XProgram except as expressly provided under this General Public License.
  155. XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
  156. Xthe Program is void, and will automatically terminate your rights to use
  157. Xthe Program under this License.  However, parties who have received
  158. Xcopies, or rights to use copies, from you under this General Public
  159. XLicense will not have their licenses terminated so long as such parties
  160. Xremain in full compliance.
  161. X
  162. X  5. By copying, distributing or modifying the Program (or any work based
  163. Xon the Program) you indicate your acceptance of this license to do so,
  164. Xand all its terms and conditions.
  165. X
  166. X  6. Each time you redistribute the Program (or any work based on the
  167. XProgram), the recipient automatically receives a license from the original
  168. Xlicensor to copy, distribute or modify the Program subject to these
  169. Xterms and conditions.  You may not impose any further restrictions on the
  170. Xrecipients' exercise of the rights granted herein.
  171. X
  172. X  7. The Free Software Foundation may publish revised and/or new versions
  173. Xof the General Public License from time to time.  Such new versions will
  174. Xbe similar in spirit to the present version, but may differ in detail to
  175. Xaddress new problems or concerns.
  176. X
  177. XEach version is given a distinguishing version number.  If the Program
  178. Xspecifies a version number of the license which applies to it and "any
  179. Xlater version", you have the option of following the terms and conditions
  180. Xeither of that version or of any later version published by the Free
  181. XSoftware Foundation.  If the Program does not specify a version number of
  182. Xthe license, you may choose any version ever published by the Free Software
  183. XFoundation.
  184. X
  185. X  8. If you wish to incorporate parts of the Program into other free
  186. Xprograms whose distribution conditions are different, write to the author
  187. Xto ask for permission.  For software which is copyrighted by the Free
  188. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  189. Xmake exceptions for this.  Our decision will be guided by the two goals
  190. Xof preserving the free status of all derivatives of our free software and
  191. Xof promoting the sharing and reuse of software generally.
  192. X
  193. X                NO WARRANTY
  194. X
  195. X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  196. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  197. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  198. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  199. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  200. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  201. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  202. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  203. XREPAIR OR CORRECTION.
  204. X
  205. X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  206. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  207. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  208. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  209. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  210. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  211. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  212. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  213. XPOSSIBILITY OF SUCH DAMAGES.
  214. X
  215. X             END OF TERMS AND CONDITIONS
  216. X
  217. X    Appendix: How to Apply These Terms to Your New Programs
  218. X
  219. X  If you develop a new program, and you want it to be of the greatest
  220. Xpossible use to humanity, the best way to achieve this is to make it
  221. Xfree software which everyone can redistribute and change under these
  222. Xterms.
  223. X
  224. X  To do so, attach the following notices to the program.  It is safest to
  225. Xattach them to the start of each source file to most effectively convey
  226. Xthe exclusion of warranty; and each file should have at least the
  227. X"copyright" line and a pointer to where the full notice is found.
  228. X
  229. X    <one line to give the program's name and a brief idea of what it does.>
  230. X    Copyright (C) 19yy  <name of author>
  231. X
  232. X    This program is free software; you can redistribute it and/or modify
  233. X    it under the terms of the GNU General Public License as published by
  234. X    the Free Software Foundation; either version 1, or (at your option)
  235. X    any later version.
  236. X
  237. X    This program is distributed in the hope that it will be useful,
  238. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  239. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  240. X    GNU General Public License for more details.
  241. X
  242. X    You should have received a copy of the GNU General Public License
  243. X    along with this program; if not, write to the Free Software
  244. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  245. X
  246. XAlso add information on how to contact you by electronic and paper mail.
  247. X
  248. XIf the program is interactive, make it output a short notice like this
  249. Xwhen it starts in an interactive mode:
  250. X
  251. X    Gnomovision version 69, Copyright (C) 19xx name of author
  252. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  253. X    This is free software, and you are welcome to redistribute it
  254. X    under certain conditions; type `show c' for details.
  255. X
  256. XThe hypothetical commands `show w' and `show c' should show the
  257. Xappropriate parts of the General Public License.  Of course, the
  258. Xcommands you use may be called something other than `show w' and `show
  259. Xc'; they could even be mouse-clicks or menu items--whatever suits your
  260. Xprogram.
  261. X
  262. XYou should also get your employer (if you work as a programmer) or your
  263. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  264. Xnecessary.  Here a sample; alter the names:
  265. X
  266. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  267. X  program `Gnomovision' (a program to direct compilers to make passes
  268. X  at assemblers) written by James Hacker.
  269. X
  270. X  <signature of Ty Coon>, 1 April 1989
  271. X  Ty Coon, President of Vice
  272. X
  273. XThat's all there is to it!
  274. END_OF_FILE
  275. if test 12487 -ne `wc -c <'LICENSE'`; then
  276.     echo shar: \"'LICENSE'\" unpacked with wrong size!
  277. fi
  278. # end of 'LICENSE'
  279. fi
  280. if test -f 'a2.3' -a "${1}" != "-c" ; then 
  281.   echo shar: Will not clobber existing file \"'a2.3'\"
  282. else
  283. echo shar: Extracting \"'a2.3'\" \(8479 characters\)
  284. sed "s/^X//" >'a2.3' <<'END_OF_FILE'
  285. X.\" $Header: a2.3,v 1.2 89/08/10 13:53:23 howard Exp $
  286. X.TH A2 "3 -lhoward" "$Revision: 1.2 $" "Howard\'s C library" "Howard\'s C library"
  287. X.SH NAME
  288. Xa2 \- convert Ada-syntax numeric literals to internal representations
  289. X.SH SYNOPSIS
  290. X.nf
  291. X.BR "#include <" stdio.h ">"
  292. X.BR "#include <" howard/port.h ">"
  293. X.BR "#include <" howard/a2.h ">"
  294. X.fi
  295. X.LP
  296. X.BR "int " "a2d ("
  297. X.IR string ,
  298. X.IR limit ,
  299. X.IR looseSyntax ,
  300. X.IR resultPointer ,
  301. X.IR endPointer " )"
  302. X.nf
  303. X.RI "bStrT " string ";"
  304. X.RI "bStrT " limit ";"
  305. X.RI "boolT " looseSyntax ";"
  306. X.BI "double *" resultPointer;
  307. X.RI "bStrT *" endPointer ;
  308. X.fi
  309. X.LP
  310. X.BR "double " "ma2d ("
  311. X.IR string ,
  312. X.IR limit ,
  313. X.IR looseSyntax ,
  314. X.IR fieldName ,
  315. X.IR endPointer " )"
  316. X.nf
  317. X.RI "bStrT " string ";"
  318. X.RI "bStrT " limit ";"
  319. X.RI "boolT " looseSyntax ";"
  320. X.RI "bStrT " fieldname ;
  321. X.RI "bStrT *" endPointer ;
  322. X.fi
  323. X.LP
  324. X.BR "double " "mra2d ("
  325. X.IR string ,
  326. X.IR limit ,
  327. X.IR looseSyntax ,
  328. X.IR fieldName ,
  329. X.IR low ,
  330. X.IR high ,
  331. X.IR endPointer " )"
  332. X.nf
  333. X.RI "bStrT " string ";"
  334. X.RI "bStrT " limit ";"
  335. X.RI "boolT " looseSyntax ";"
  336. X.RI "bStrT " fieldName ;
  337. X.BI "double " low;
  338. X.BI "double " high;
  339. X.RI "bStrT *" endPointer ;
  340. X.fi
  341. X.LP
  342. X.BR "int " "a2i ("
  343. X.IR string ,
  344. X.IR limit ,
  345. X.IR looseSyntax ,
  346. X.IR resultPointer ,
  347. X.IR endPointer " )"
  348. X.nf
  349. X.RI "bStrT " string ";"
  350. X.RI "bStrT " limit ";"
  351. X.RI "boolT " looseSyntax ";"
  352. X.BI "int *" resultPointer;
  353. X.RI "bStrT *" endPointer ;
  354. X.fi
  355. X.LP
  356. X.BR "int " "ma2i ("
  357. X.IR string ,
  358. X.IR limit ,
  359. X.IR looseSyntax ,
  360. X.IR fieldName ,
  361. X.IR endPointer " )"
  362. X.nf
  363. X.RI "bStrT " string ";"
  364. X.RI "bStrT " limit ";"
  365. X.RI "boolT " looseSyntax ";"
  366. X.RI "bStrT " fieldname ;
  367. X.RI "bStrT *" endPointer ;
  368. X.fi
  369. X.LP
  370. X.BR "int " "mra2i ("
  371. X.IR string ,
  372. X.IR limit ,
  373. X.IR looseSyntax ,
  374. X.IR fieldName ,
  375. X.IR low ,
  376. X.IR high ,
  377. X.IR endPointer " )"
  378. X.nf
  379. X.RI "bStrT " string ";"
  380. X.RI "bStrT " limit ";"
  381. X.RI "boolT " looseSyntax ";"
  382. X.RI "bStrT " fieldName ;
  383. X.BI "int " low;
  384. X.BI "int " high;
  385. X.RI "bStrT *" endPointer ;
  386. X.fi
  387. X.LP
  388. X.BR "int " "a2l ("
  389. X.IR string ,
  390. X.IR limit ,
  391. X.IR looseSyntax ,
  392. X.IR resultPointer ,
  393. X.IR endPointer " )"
  394. X.nf
  395. X.RI "bStrT " string ";"
  396. X.RI "bStrT " limit ";"
  397. X.RI "boolT " looseSyntax ";"
  398. X.BI "long *" resultPointer;
  399. X.RI "bStrT *" endPointer ;
  400. X.fi
  401. X.LP
  402. X.BR "long " "ma2l ("
  403. X.IR string ,
  404. X.IR limit ,
  405. X.IR looseSyntax ,
  406. X.IR fieldName ,
  407. X.IR endPointer " )"
  408. X.nf
  409. X.RI "bStrT " string ";"
  410. X.RI "bStrT " limit ";"
  411. X.RI "boolT " looseSyntax ";"
  412. X.RI "bStrT " fieldname ;
  413. X.RI "bStrT *" endPointer ;
  414. X.fi
  415. X.LP
  416. X.BR "long " "mra2l ("
  417. X.IR string ,
  418. X.IR limit ,
  419. X.IR looseSyntax ,
  420. X.IR fieldName ,
  421. X.IR low ,
  422. X.IR high ,
  423. X.IR endPointer " )"
  424. X.nf
  425. X.RI "bStrT " string ";"
  426. X.RI "bStrT " limit ";"
  427. X.RI "boolT " looseSyntax ";"
  428. X.RI "bStrT " fieldName ;
  429. X.BI "long " low;
  430. X.BI "long " high;
  431. X.RI "bStrT *" endPointer ;
  432. X.fi
  433. X.LP
  434. X.BR "int " "a2u ("
  435. X.IR string ,
  436. X.IR limit ,
  437. X.IR looseSyntax ,
  438. X.IR resultPointer ,
  439. X.IR endPointer " )"
  440. X.nf
  441. X.RI "bStrT " string ";"
  442. X.RI "bStrT " limit ";"
  443. X.RI "boolT " looseSyntax ";"
  444. X.BI "unsigned *" resultPointer;
  445. X.RI "bStrT *" endPointer ;
  446. X.fi
  447. X.LP
  448. X.BR "unsigned " "ma2u ("
  449. X.IR string ,
  450. X.IR limit ,
  451. X.IR looseSyntax ,
  452. X.IR fieldName ,
  453. X.IR endPointer " )"
  454. X.nf
  455. X.RI "bStrT " string ";"
  456. X.RI "bStrT " limit ";"
  457. X.RI "boolT " looseSyntax ";"
  458. X.RI "bStrT " fieldname ;
  459. X.RI "bStrT *" endPointer ;
  460. X.fi
  461. X.LP
  462. X.BR "unsigned " "mra2u ("
  463. X.IR string ,
  464. X.IR limit ,
  465. X.IR looseSyntax ,
  466. X.IR fieldName ,
  467. X.IR low ,
  468. X.IR high ,
  469. X.IR endPointer " )"
  470. X.nf
  471. X.RI "bStrT " string ";"
  472. X.RI "bStrT " limit ";"
  473. X.RI "boolT " looseSyntax ";"
  474. X.RI "bStrT " fieldName ;
  475. X.BI "unsigned " low;
  476. X.BI "unsigned " high;
  477. X.RI "bStrT *" endPointer ;
  478. X.fi
  479. X.LP
  480. X.BR "int " "a2ul ("
  481. X.IR string ,
  482. X.IR limit ,
  483. X.IR looseSyntax ,
  484. X.IR resultPointer ,
  485. X.IR endPointer " )"
  486. X.nf
  487. X.RI "bStrT " string ";"
  488. X.RI "bStrT " limit ";"
  489. X.RI "boolT " looseSyntax ";"
  490. X.RI "ulongT *" resultPointer ;
  491. X.RI "bStrT *" endPointer ;
  492. X.fi
  493. X.LP
  494. XulongT ma2ul (
  495. X.IR string ,
  496. X.IR limit ,
  497. X.IR looseSyntax ,
  498. X.IR fieldName ,
  499. X.IR endPointer " )"
  500. X.nf
  501. X.RI "bStrT " string ";"
  502. X.RI "bStrT " limit ";"
  503. X.RI "boolT " looseSyntax ";"
  504. X.RI "bStrT " fieldname ;
  505. X.RI "bStrT *" endPointer ;
  506. X.fi
  507. X.LP
  508. XulongT mra2ul (
  509. X.IR string ,
  510. X.IR limit ,
  511. X.IR looseSyntax ,
  512. X.IR fieldName ,
  513. X.IR low ,
  514. X.IR high ,
  515. X.IR endPointer " )"
  516. X.nf
  517. X.RI "bStrT " string ";"
  518. X.RI "bStrT " limit ";"
  519. X.RI "boolT " looseSyntax ";"
  520. X.RI "bStrT " fieldName ;
  521. X.RI "ulongT " low ;
  522. X.RI "ulongT " high ;
  523. X.RI "bStrT *" endPointer ;
  524. X.fi
  525. X.SH COPYRIGHT
  526. XCopyright \(co 1989 Howard Lee Gayle
  527. X.SH DESCRIPTION
  528. XThese functions convert Ada-syntax numeric literals to internal
  529. Xrepresentations.
  530. XThey check for syntax errors and overflow.
  531. XThe syntax of Ada numeric literals is (from the Language
  532. XReference Manual [LRM]):
  533. X.nf
  534. X   numeric_literal ::= decimal_literal | based_literal
  535. X   decimal_literal ::= integer [.integer] [exponent]
  536. X   integer ::= digit {[underline] digit}
  537. X   exponent ::= E [+] integer | E - integer
  538. X   based_literal ::= base # based_integer [.based_integer] # [exponent]
  539. X   base ::= integer
  540. X   based_integer ::= extended_digit {[underline] extended_digit}
  541. X   extended_digit ::= digit | letter
  542. X.fi
  543. XA numeric literal may be preceded by an optional sign.
  544. X.PP
  545. XFor the appropriate functions,
  546. X.I string
  547. Xis the string representation of the numeric literal.
  548. XIf
  549. X.I limit
  550. Xis not NULL, then it is taken as a pointer to the byte in
  551. X.I string
  552. Xafter the last byte to be treated as part of the literal.
  553. XIf
  554. X.I looseSyntax
  555. Xis FALSE, then the literal must strictly follow Ada syntax.
  556. XOtherwise, leading white space is permitted, no digit is
  557. Xrequired either before or after a radix point, and conversion
  558. Xstops when a byte is encountered that can not be part of the
  559. Xliteral.
  560. XIf
  561. X.I resultPointer
  562. Xis not NULL, and if the conversion is successful, then the
  563. Xinternal value is stored in the area to which
  564. X.I resultPointer
  565. Xpoints.
  566. XIf
  567. X.I endPointer
  568. Xis not NULL, then a pointer to the byte in
  569. X.I string
  570. Xthat ended the conversion is stored in the area to which
  571. X.I endPointer
  572. Xpoints.
  573. X.I fieldName
  574. Xis a string used to identify the conversion in possible error
  575. Xmessages,
  576. X.I e.g.
  577. X"Body font size."
  578. XIn functions starting with mr, the
  579. X.I low
  580. Xand
  581. X.I high
  582. Xparameters specify that the result must be in the range
  583. X.RI [ low ", " high ].
  584. X.SH RETURNS
  585. XThe functions not starting with m return 0 on success,
  586. XEINVAL on invalid arguments,
  587. XEDOM on syntax error,
  588. Xand ERANGE on overflow.
  589. XThe funtions starting with m return the internal value of the
  590. Xnumeric literal on success, and call
  591. X.IR malf1 (3)
  592. Xon error.
  593. X.SH EXAMPLES
  594. XHere are some examples of numeric literals from the LRM:
  595. X.nf
  596. X12   0   1E6   123_456
  597. X12.0   0.0   0.456   3.14159_26
  598. X1.34E-12   1.0E+6
  599. X2#1111_1111#   16#FF#   016#0FF#
  600. X16#E#E1   2#1110_0000#
  601. X.fi
  602. X.PP
  603. XThis very simple program converts its input to decimal:
  604. X.nf
  605. Xmain (argc, argv)
  606. Xint    argc; /* Number of arguments.*/
  607. XbStrT *argv; /* Points to array of argument strings.*/
  608. X{
  609. Xprintf ("%ld\en", ma2l (argv[1], NULBSTR, FALSE, S("arg"), (bStrT *) NULL));
  610. X}
  611. X.fi
  612. X.SH "SEE ALSO"
  613. X.IR malf (3 \-lhoward),
  614. X.IR simultipre (3 \-lhoward),
  615. X.IR strtod (3),
  616. X.IR strtol (3),
  617. X.IR "Ada Language Reference Manual" .
  618. X.SH DIAGNOSTICS
  619. XIn case of syntax error,
  620. X.IR malf (3)
  621. Xplaces a veritcal line in the input string at the position of
  622. Xthe error.
  623. X.SH BUGS
  624. XBased real literals are not implemented.
  625. X.PP
  626. XThe functions ending in
  627. X.I a2d
  628. Xcall
  629. X.IR atof (3)
  630. Xto do the actual conversion.
  631. XOn some systems, atof does not check for overflow.
  632. X.SH RATIONALE
  633. XWhatever one thinks of the rest of the language, Ada's numeric
  634. Xliteral syntax is consistent and logical.
  635. XRadix selection is not
  636. X.IR "ad hoc" ,
  637. Xas in some other languages.
  638. XThe underscore greatly increases readability of long literals,
  639. Xso that even binary literals can be useful,
  640. X.I e.g.
  641. Xfor bit registers.
  642. XInteger exponents can also increase readability.
  643. XFor example, 2 to the 31st power can be written
  644. Xstraightforwardly as 2#1#E31.
  645. X.SH LICENSE
  646. XThis program is free software; you can redistribute it and/or modify
  647. Xit under the terms of the GNU General Public License version 1,
  648. Xas published by the Free Software Foundation.
  649. X.PP
  650. XThis program is distributed in the hope that it will be useful,
  651. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  652. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  653. XGNU General Public License for more details.
  654. X.PP
  655. XYou should have received a copy of the GNU General Public License
  656. Xalong with this program; if not, write to the Free Software
  657. XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  658. X.SH AUTHOR
  659. XHoward Gayle,
  660. XTN/ETX/T/BG,
  661. XEricsson Telecom AB,
  662. XS-126 25 Stockholm,
  663. XSweden,
  664. Xhoward@ericsson.se,
  665. Xuunet!ericsson.se!howard,
  666. XPhone: +46 8 719 5565,
  667. XFAX: +46 8 719 9598,
  668. XTelex: 14910 ERIC S
  669. END_OF_FILE
  670. if test 8479 -ne `wc -c <'a2.3'`; then
  671.     echo shar: \"'a2.3'\" unpacked with wrong size!
  672. fi
  673. # end of 'a2.3'
  674. fi
  675. if test -f 'a2d.c' -a "${1}" != "-c" ; then 
  676.   echo shar: Will not clobber existing file \"'a2d.c'\"
  677. else
  678. echo shar: Extracting \"'a2d.c'\" \(9807 characters\)
  679. sed "s/^X//" >'a2d.c' <<'END_OF_FILE'
  680. X/*
  681. X * a2d - convert Ada-syntax real literal to double
  682. X */
  683. X
  684. X#ifndef lint
  685. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  686. X#endif lint
  687. X
  688. X/*
  689. X * This program is free software; you can redistribute it and/or modify
  690. X * it under the terms of the GNU General Public License version 1,
  691. X * as published by the Free Software Foundation.
  692. X *
  693. X * This program is distributed in the hope that it will be useful,
  694. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  695. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  696. X * GNU General Public License for more details.
  697. X *
  698. X * You should have received a copy of the GNU General Public License
  699. X * along with this program; if not, write to the Free Software
  700. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  701. X */
  702. X
  703. X#include <stdio.h>
  704. X#include <howard/port.h>
  705. X#include <howard/version.h>
  706. X
  707. XMODVER ("@(#)$Header: a2d.c,v 1.7 89/08/09 18:13:20 howard Exp $");
  708. X
  709. X#include <ctype.h>
  710. X#include <errno.h>
  711. X#include <string.h>
  712. X#include <howard/a2.h>
  713. X#include <howard/malf.h>
  714. X#include <howard/registers.i>
  715. X#include <howard/simultipre.i>
  716. X#include <howard/smp.h>
  717. X
  718. XPUBLIC int a2d (str, lim, synok, res, end)
  719. XR7  bStrT   str;   /* Input string.*/
  720. XR8  bStrT   lim;   /* Don't pass this.*/
  721. XR5  boolT   synok; /* Accept non-fatal syntax errors.*/
  722. XR9  double *res;   /* Points to where to store result.*/
  723. XR11 bStrT  *end;   /* End pointer stored here.*/
  724. X
  725. X/* Function:
  726. X *    
  727. X * Algorithm:
  728. X *    Scan str with finite state automaton.  Build up argument to atof().
  729. X *    Call atof to do the actual conversion.
  730. X * Returns:
  731. X *    
  732. X * Notes:
  733. X *    1) Should not use atof, since it doesn't always set errno correctly.
  734. X */
  735. X{
  736. X/* States: */
  737. X#define S_BEG   (-1) /* Start.*/
  738. X#define S_BINT  (-2) /* Start of integer part.*/
  739. X#define S_IINT  (-3) /* In integer part.*/
  740. X#define S_BFRAC (-4) /* Start of fractional part.*/
  741. X#define S_IFRAC (-5) /* In fractional part.*/
  742. X#define S_BEXP  (-6) /* Start of exponent.*/
  743. X#define S_FEXP  (-7) /* Expecting first digit of exponent.*/
  744. X#define S_IEXP  (-8) /* In exponent.*/
  745. XR4     rcharT c;     /* Current character.*/
  746. X       double d;     /* atof(3) returns this.*/
  747. XR2     int    i;     /* General purpose.*/
  748. XR1     cStrT  p;     /* Steps through buf[].*/
  749. XR6     cStrT  pe;    /* Points to end of buf[].*/
  750. XR3     int    s;     /* State or return code.*/
  751. XR10    int    se;    /* Save errno.*/
  752. Xstatic bStrT  dt[] = /* Digit table.*/
  753. X   {
  754. X   S("_"),
  755. X   S("+"),
  756. X   S("-"),
  757. X   S("."),
  758. X   S("0"),
  759. X   S("1"),
  760. X   S("2"),
  761. X   S("3"),
  762. X   S("4"),
  763. X   S("5"),
  764. X   S("6"),
  765. X   S("7"),
  766. X   S("8"),
  767. X   S("9"),
  768. X   NULBSTR
  769. X   };
  770. Xchar buf[512]; /* Accumulate string here.*/
  771. Xextern double atof(); /* (3).*/
  772. X
  773. Xp = buf;
  774. Xpe = &buf[sizeof (buf) - 2];
  775. Xs = ((NULBSTR == str) ? EINVAL : S_BEG);
  776. Xwhile (s < 0)
  777. X   {
  778. X   c = ((str == lim) ? EOS : B(*str));
  779. X   i = ((EOS == c) ? -2 : smpdtl (c, dt));
  780. X   switch (s)
  781. X      {
  782. X      case S_BEG:
  783. X         if (DT_PLUS == i)
  784. X            s = S_BINT;
  785. X         else if (DT_NEG == i)
  786. X            {
  787. X            *p++ = '-';
  788. X            s = S_BINT;
  789. X            }
  790. X         else if (DT_ZERO <= i)
  791. X            {
  792. X            *p++ = '0' + i - DT_ZERO;
  793. X            s = S_IINT;
  794. X            }
  795. X         else if (synok && (DT_RADP == i))
  796. X            {
  797. X            *p++ = '0';
  798. X            *p++ = '.';
  799. X            s = S_BFRAC;
  800. X            }
  801. X         else if (!synok || !isascii (c) || !isspace (c))
  802. X            s = EDOM; /* Leading white space OK if synok set.*/
  803. X         break;
  804. X      case S_BINT:
  805. X         if (DT_ZERO <= i)
  806. X            {
  807. X            *p++ = '0' + i - DT_ZERO;
  808. X            s = S_IINT;
  809. X            }
  810. X         else if (synok && (DT_RADP == i))
  811. X            {
  812. X            *p++ = '0';
  813. X            *p++ = '.';
  814. X            s = S_BFRAC;
  815. X            }
  816. X         else
  817. X            s = EDOM;
  818. X         break;
  819. X      case S_IINT:
  820. X         if (DT_ZERO <= i)
  821. X            {
  822. X            if (p == pe) s = EDOM; else *p++ = '0' + i - DT_ZERO;
  823. X            }
  824. X         else if (DT_RADP == i)
  825. X            {
  826. X            if (p == pe)
  827. X               s = EDOM;
  828. X            else
  829. X               {
  830. X               *p++ = '.';
  831. X               s = S_BFRAC;
  832. X               }
  833. X            }
  834. X         else if (DT_IGN != i)
  835. X            switch (c)
  836. X               {
  837. X               case 'e':
  838. X               case 'E':
  839. X                  if (!synok || (p == pe))
  840. X                     s = EDOM;
  841. X                  else
  842. X                     {
  843. X                     *p++ = 'E';
  844. X                     s = S_BEXP;
  845. X                     }
  846. X                  break;
  847. X               default:
  848. X                  s = (synok ? SUCCESS : EDOM);
  849. X                  break;
  850. X               }
  851. X         break;
  852. X      case S_BFRAC:
  853. X         if (DT_ZERO <= i)
  854. X            {
  855. X            if (p == pe)
  856. X               s = EDOM;
  857. X            else
  858. X               {
  859. X               *p++ = '0' + i - DT_ZERO;
  860. X               s = S_IFRAC;
  861. X               }
  862. X            }
  863. X         else
  864. X            s = (synok ? SUCCESS : EDOM);
  865. X         break;
  866. X      case S_IFRAC:
  867. X         if (DT_ZERO <= i)
  868. X            {
  869. X            if (p == pe) s = EDOM; else *p++ = '0' + i - DT_ZERO;
  870. X            }
  871. X         else if (DT_IGN != i)
  872. X            switch (c)
  873. X               {
  874. X               case EOS:
  875. X                  s = SUCCESS;
  876. X                  break;
  877. X               case 'e':
  878. X               case 'E':
  879. X                  if (p == pe)
  880. X                     s = EDOM;
  881. X                  else
  882. X                     {
  883. X                     *p++ = 'E';
  884. X                     s = S_BEXP;
  885. X                     }
  886. X                  break;
  887. X               default:
  888. X                  s = (synok ? SUCCESS : EDOM);
  889. X                  break;
  890. X               }
  891. X         break;
  892. X      case S_BEXP:
  893. X         if (DT_PLUS == i)
  894. X            s = S_FEXP;
  895. X         else if (DT_NEG == i)
  896. X            {
  897. X            if (p == pe)
  898. X               s = EDOM;
  899. X            else
  900. X               {
  901. X               *p++ = '-';
  902. X               s = S_FEXP;
  903. X               }
  904. X            }
  905. X         else if (DT_ZERO <= i)
  906. X            {
  907. X            if (p == pe)
  908. X               s = EDOM;
  909. X            else
  910. X               {
  911. X               *p++ = '0' + i - DT_ZERO;
  912. X               s = S_IEXP;
  913. X               }
  914. X            }
  915. X         else if (synok)
  916. X            {
  917. X            --p;
  918. X            s = SUCCESS;
  919. X            }
  920. X         else
  921. X            s = EDOM;
  922. X         break;
  923. X      case S_FEXP:
  924. X         if (DT_ZERO <= i)
  925. X            {
  926. X            if (p == pe)
  927. X               s = EDOM;
  928. X            else
  929. X               {
  930. X               *p++ = '0' + i - DT_ZERO;
  931. X               s = S_IEXP;
  932. X               }
  933. X            }
  934. X         else if (synok)
  935. X            {
  936. X            p = strrchr (buf, 'E');
  937. X            s = SUCCESS;
  938. X            }
  939. X         else
  940. X            s = EDOM;
  941. X         break;
  942. X      case S_IEXP:
  943. X         if (DT_ZERO <= i)
  944. X            {
  945. X            if (p == pe) s = EDOM; else *p++ = '0' + i - DT_ZERO;
  946. X            }
  947. X         else if (DT_IGN != i)
  948. X            {
  949. X            s = (((EOS == c) || synok) ? SUCCESS : EDOM);
  950. X            }
  951. X         break;
  952. X      default:
  953. X         malf1 ("a2d: unknown state");
  954. X         break;
  955. X      }
  956. X   if ((s < 0) && (lim != str)) ++str;
  957. X   }
  958. Xif (SUCCESS == s)
  959. X   {
  960. X   *p = EOS;
  961. X#ifdef BADATOF
  962. X   if (((double *) NULL) != res) *res = atof (buf);
  963. X#else BADATOF
  964. X   se = errno;
  965. X   errno = SUCCESS;
  966. X   d = atof (buf);
  967. X   s = errno;
  968. X/* if (ERANGE == s) FPRINTF (stderr, "a2d ERANGE: atof (%s) = %G\n", buf, d);*/
  969. X   errno = se;
  970. X   if ((SUCCESS == s) && (((double *) NULL) != res)) *res = d;
  971. X#endif BADATOF
  972. X   }
  973. Xif (((bStrT *) NULL) != end) *end = str;
  974. Xreturn (s);
  975. X}
  976. X
  977. X#ifdef TEST
  978. X#include <howard/usage.h>
  979. X
  980. XMAINVER ("@(#)$Header: a2d.c,v 1.7 89/08/09 18:13:20 howard Exp $");
  981. XUSAGE ("");
  982. X
  983. XPRIVATE void t (num, str, limoff, synok, xrc, xres, xendoff)
  984. Xint    num;     /* Test number.*/
  985. XbStrT  str;     /* str argument.*/
  986. Xint    limoff;  /* Limit offset, -1 for none.*/
  987. XboolT  synok;   /* synok argument.*/
  988. Xint    xrc;     /* Expected return code.*/
  989. Xdouble xres;    /* Expected result.*/
  990. Xint    xendoff; /* Expected end offset.*/
  991. X{
  992. Xint    rc;  /* Return code.*/
  993. Xdouble res; /* Result stored here.*/
  994. XbStrT  end; /* End string stored here.*/
  995. X
  996. Xrc = a2d (str, (limoff < 0) ? NULBSTR : str + limoff, synok, &res, &end);
  997. Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
  998. Xif ((0 == rc) && (0 == xrc) && (res != xres))
  999. X   PRINTF ("%d: res %f expected %f\n", num, res, xres);
  1000. Xif (xendoff < 0) xendoff = strlen (str);
  1001. Xif ((end - str) != xendoff)
  1002. X   PRINTF ("%d: end %s expected %s\n", num, end, str + xendoff);
  1003. X}
  1004. X
  1005. XPUBLIC int main (argc, argv)
  1006. Xint    argc; /* Number of arguments.*/
  1007. XbStrT *argv; /* Points to array of argument strings.*/
  1008. X{
  1009. Xif (1 != argc) usage();
  1010. X/*num      str           limoff syn  rc    res  end */
  1011. Xt(__LINE__,"12.0",            -1, 0, 0,      12.0,  -1);
  1012. Xt(__LINE__,"+12.0",           -1, 0, 0,      12.0,  -1);
  1013. Xt(__LINE__,"0.0",             -1, 0, 0,      0.0,  -1);
  1014. Xt(__LINE__,"-0.0",            -1, 0, 0,      0.0,  -1);
  1015. Xt(__LINE__,"0.456",           -1, 0, 0,      0.456,  -1);
  1016. Xt(__LINE__,"+.456",           -1, 1, 0,      0.456,  -1);
  1017. Xt(__LINE__,"456",             -1, 1, 0,      456.0,  -1);
  1018. Xt(__LINE__,"456._",           -1, 1, 0,      456.0,  4);
  1019. Xt(__LINE__," \t.456",         -1, 1, 0,      0.456,  -1);
  1020. Xt(__LINE__,"3.14159_26",      -1, 0, 0,      3.1415926,  -1);
  1021. Xt(__LINE__,"1.34E-12",        -1, 0, 0,      1.34E-12,  -1);
  1022. Xt(__LINE__,"1.34e-12",        -1, 0, 0,      1.34E-12,  -1);
  1023. Xt(__LINE__,"1.0E+6",          -1, 0, 0,      1.0E+6,  -1);
  1024. Xt(__LINE__,"1E6",             -1, 1, 0,      1.0E+6,  -1);
  1025. Xt(__LINE__,NULBSTR,            0, 0, EINVAL, 0.0,   0);
  1026. Xt(__LINE__,"0",                0, 0, EDOM,   0.0,   0);
  1027. Xt(__LINE__,"_0.0",            -1, 0, EDOM,   0.0,   0);
  1028. Xt(__LINE__,"-_0.0",           -1, 0, EDOM,   0.0,   1);
  1029. Xmfflush (stdout, S("Standard Output"));
  1030. Xexit (SUCCESS);
  1031. X
  1032. X#ifdef lint
  1033. Xreturn (SUCCESS);
  1034. X#endif
  1035. X}
  1036. X#endif
  1037. END_OF_FILE
  1038. if test 9807 -ne `wc -c <'a2d.c'`; then
  1039.     echo shar: \"'a2d.c'\" unpacked with wrong size!
  1040. fi
  1041. # end of 'a2d.c'
  1042. fi
  1043. if test -f 'a2smp.c' -a "${1}" != "-c" ; then 
  1044.   echo shar: Will not clobber existing file \"'a2smp.c'\"
  1045. else
  1046. echo shar: Extracting \"'a2smp.c'\" \(9977 characters\)
  1047. sed "s/^X//" >'a2smp.c' <<'END_OF_FILE'
  1048. X/*
  1049. X * a2smp - convert Ada-syntax integer literal to SMP
  1050. X */
  1051. X
  1052. X#ifndef lint
  1053. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  1054. X#endif lint
  1055. X
  1056. X/*
  1057. X * This program is free software; you can redistribute it and/or modify
  1058. X * it under the terms of the GNU General Public License version 1,
  1059. X * as published by the Free Software Foundation.
  1060. X *
  1061. X * This program is distributed in the hope that it will be useful,
  1062. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1063. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1064. X * GNU General Public License for more details.
  1065. X *
  1066. X * You should have received a copy of the GNU General Public License
  1067. X * along with this program; if not, write to the Free Software
  1068. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1069. X */
  1070. X
  1071. X#include <stdio.h>
  1072. X#include <howard/port.h>
  1073. X#include <howard/version.h>
  1074. X
  1075. XMODVER ("@(#)$Header: a2smp.c,v 1.11 89/08/15 13:33:10 howard Exp $");
  1076. X
  1077. X#include <ctype.h>
  1078. X#include <errno.h>
  1079. X#include <howard/malf.h>
  1080. X#include <howard/registers.i>
  1081. X#include <howard/simultipre.i>
  1082. X#include <howard/smp.h>
  1083. X
  1084. XPUBLIC int a2smp (str, lim, synok, res, end)
  1085. XR6  bStrT  str;   /* Input string.*/
  1086. XR7  bStrT  lim;   /* Don't pass this.*/
  1087. XR5  boolT  synok; /* Accept non-fatal syntax errors.*/
  1088. XR9  smpT  *res;   /* Points to where to store result.*/
  1089. XR10 bStrT *end;   /* End pointer stored here.*/
  1090. X
  1091. X/* Function:
  1092. X *    
  1093. X * Algorithm:
  1094. X *    Finite state automaton.
  1095. X * Returns:
  1096. X *    
  1097. X * Notes:
  1098. X *    
  1099. X */
  1100. X{
  1101. X/* States: */
  1102. X#define S_BEG   (-1) /* Start.*/
  1103. X#define S_BBASE (-2) /* Start of base or mantissa base.*/
  1104. X#define S_IBASE (-3) /* In base or mantissa.*/
  1105. X#define S_BMANT (-4) /* Start of mantissa.*/
  1106. X#define S_IMANT (-5) /* In mantissa.*/
  1107. X#define S_EMANT (-6) /* At end of mantissa.*/
  1108. X#define S_BEXP  (-7) /* Start of exponent.*/
  1109. X#define S_FEXP  (-8) /* Expecting first digit of exponent.*/
  1110. X#define S_IEXP  (-9) /* In exponent.*/
  1111. XR3     rcharT   c;           /* Current character.*/
  1112. XR1     int      i;           /* General purpose.*/
  1113. XR8     boolT    neg = FALSE; /* Minus sign at start.*/
  1114. XR4     unsigned rad = 10;    /* Radix.*/
  1115. X       long     l;           /* General purpose.*/
  1116. XR2     int      s;           /* State or return code.*/
  1117. X       smpT     baseSmp;     /* SMP of base or mantissa.*/
  1118. X       smpT     expSmp;      /* SMP of exponent.*/
  1119. Xstatic smpT     smp0;        /* Zero SMP, for initialization.*/
  1120. Xstatic bStrT dt[] =          /* Digit table.*/
  1121. X   {
  1122. X   S("_"),
  1123. X   S("+"),
  1124. X   S("-"),
  1125. X   S(""), /* Only integers, no radix point.*/
  1126. X   S("0"),
  1127. X   S("1"),
  1128. X   S("2"),
  1129. X   S("3"),
  1130. X   S("4"),
  1131. X   S("5"),
  1132. X   S("6"),
  1133. X   S("7"),
  1134. X   S("8"),
  1135. X   S("9"),
  1136. X   S("aA"),
  1137. X   S("bB"),
  1138. X   S("cC"),
  1139. X   S("dD"),
  1140. X   S("eE"),
  1141. X   S("fF"),
  1142. X   NULBSTR
  1143. X   };
  1144. X
  1145. XbaseSmp = smp0;
  1146. XexpSmp = smp0;
  1147. Xs = ((NULBSTR == str) ? EINVAL : S_BEG);
  1148. Xwhile (s < 0)
  1149. X   {
  1150. X   c = ((str == lim) ? EOS : B(*str));
  1151. X   i = ((EOS == c) ? -2 : smpdtl (c, dt));
  1152. X   switch (s)
  1153. X      {
  1154. X      case S_BEG:
  1155. X         if (DT_PLUS == i)
  1156. X            s = S_BBASE;
  1157. X         else if (DT_NEG == i)
  1158. X            {
  1159. X            neg = TRUE;
  1160. X            s = S_BBASE;
  1161. X            }
  1162. X         else if ((DT_ZERO <= i) && (i <= (DT_ZERO + 9)))
  1163. X            {
  1164. X            (void) smpdig (i - DT_ZERO, rad, &baseSmp);
  1165. X            s = S_IBASE;
  1166. X            }
  1167. X         else if (!synok || !isascii (c) || !isspace (c))
  1168. X            s = EDOM; /* Leading white space OK if synok set.*/
  1169. X         break;
  1170. X      case S_BBASE:
  1171. X         if ((DT_ZERO <= i) && (i <= (DT_ZERO + 9)))
  1172. X            {
  1173. X            (void) smpdig (i - DT_ZERO, rad, &baseSmp);
  1174. X            s = S_IBASE;
  1175. X            }
  1176. X         else
  1177. X            s = EDOM;
  1178. X         break;
  1179. X      case S_IBASE:
  1180. X         if ((DT_ZERO <= i) && (i <= (DT_ZERO + 9)))
  1181. X            {
  1182. X            if (!smpdig (i - DT_ZERO, rad, &baseSmp)) s = ERANGE;
  1183. X            }
  1184. X         else if (DT_IGN != i)
  1185. X            switch (c)
  1186. X               {
  1187. X               case '#':
  1188. X                  s = smp2l (&baseSmp, &l);
  1189. X                  if (SUCCESS == s)
  1190. X                     {
  1191. X                     if ((l < 2) || (l > 16)) s = EDOM;
  1192. X                     else
  1193. X                        {
  1194. X                        rad = l;
  1195. X                        baseSmp = smp0;
  1196. X                        s = S_BMANT;
  1197. X                        }
  1198. X                     }
  1199. X                  break;
  1200. X               case 'e':
  1201. X               case 'E':
  1202. X                  s = S_BEXP;
  1203. X                  break;
  1204. X               case EOS:
  1205. X                  s = SUCCESS;
  1206. X                  break;
  1207. X               default:
  1208. X                  s = (synok ? SUCCESS : EDOM);
  1209. X                  break;
  1210. X               }
  1211. X         break;
  1212. X      case S_BMANT:
  1213. X         if (i < DT_ZERO)
  1214. X            s = EDOM;
  1215. X         else
  1216. X            {
  1217. X            i -= DT_ZERO;
  1218. X            if (i >= rad)
  1219. X               s = EDOM;
  1220. X            else if (smpdig (i, rad, &baseSmp))
  1221. X               s = S_IMANT;
  1222. X            else
  1223. X               s = ERANGE;
  1224. X            }
  1225. X         break;
  1226. X      case S_IMANT:
  1227. X         if (DT_ZERO <= i)
  1228. X            {
  1229. X            i -= DT_ZERO;
  1230. X            if (i >= rad) s = EDOM;
  1231. X            else if (!smpdig (i, rad, &baseSmp)) s = ERANGE;
  1232. X            }
  1233. X         else if ('#' == c)
  1234. X            s = S_EMANT;
  1235. X         else if (DT_IGN != i)
  1236. X            s = EDOM;
  1237. X         break;
  1238. X      case S_EMANT:
  1239. X         switch (c)
  1240. X            {
  1241. X            case 'e':
  1242. X            case 'E':
  1243. X               s = S_BEXP;
  1244. X               break;
  1245. X            case EOS:
  1246. X               s = SUCCESS;
  1247. X               break;
  1248. X            default:
  1249. X               s = (synok ? SUCCESS : EDOM);
  1250. X               break;
  1251. X            }
  1252. X         break;
  1253. X      case S_BEXP:
  1254. X         if (DT_PLUS == i)
  1255. X            s = S_FEXP;
  1256. X         else if ((DT_ZERO <= i) && (i <= (DT_ZERO + 9)))
  1257. X            {
  1258. X            (void) smpdig (i - DT_ZERO, 10, &expSmp);
  1259. X            s = S_IEXP;
  1260. X            }
  1261. X         else
  1262. X            s = EDOM;
  1263. X         break;
  1264. X      case S_FEXP:
  1265. X         if ((DT_ZERO <= i) && (i <= (DT_ZERO + 9)))
  1266. X            {
  1267. X            (void) smpdig (i - DT_ZERO, 10, &expSmp);
  1268. X            s = S_IEXP;
  1269. X            }
  1270. X         else
  1271. X            s = EDOM;
  1272. X         break;
  1273. X      case S_IEXP:
  1274. X         if ((DT_ZERO <= i) && (i <= (DT_ZERO + 9)))
  1275. X            {
  1276. X            if (!smpdig (i - DT_ZERO, 10, &expSmp)) s = ERANGE;
  1277. X            }
  1278. X         else if (DT_IGN != i)
  1279. X            {
  1280. X            if ((EOS != c) && !synok)
  1281. X               s = EDOM;
  1282. X            else
  1283. X               {
  1284. X               s = smp2l (&expSmp, &l);
  1285. X               for (; (SUCCESS == s) && (0L != l); --l)
  1286. X                  if (!smpdig (0, rad, &baseSmp)) s = ERANGE;
  1287. X               }
  1288. X            }
  1289. X         break;
  1290. X      default:
  1291. X         malf1 ("a2smp: unknown state");
  1292. X         break;
  1293. X      }
  1294. X   if ((s < 0) && (lim != str)) ++str;
  1295. X   }
  1296. Xif ((SUCCESS == s) && (((smpT *) NULL) != res))
  1297. X   {
  1298. X   baseSmp.smp_neg = neg;
  1299. X   *res = baseSmp;
  1300. X   }
  1301. Xif (((bStrT *) NULL) != end) *end = str;
  1302. Xreturn (s);
  1303. X}
  1304. X
  1305. X#ifdef TEST
  1306. X#include <howard/usage.h>
  1307. X
  1308. XMAINVER ("@(#)$Header: a2smp.c,v 1.11 89/08/15 13:33:10 howard Exp $");
  1309. XUSAGE ("string");
  1310. X
  1311. X#include <limits.h>
  1312. X#include <string.h>
  1313. X
  1314. XPRIVATE void t (num, str, limoff, synok, xrc, xneg, xhi, xlo, xendoff)
  1315. Xint num; /* Test number.*/
  1316. XbStrT str; /* str argument.*/
  1317. Xint limoff; /* Limit offset, -1 for none.*/
  1318. XboolT synok; /* synok argument.*/
  1319. Xint xrc; /* Expected return code.*/
  1320. XboolT xneg; /* Expected result sign.*/
  1321. XsmpElT xhi; /* Expected high half of result.*/
  1322. XsmpElT xlo; /* Expected low half of result.*/
  1323. Xint xendoff; /* Expected end offset.*/
  1324. X{
  1325. Xint rc; /* Return code.*/
  1326. XsmpT res; /* Result stored here.*/
  1327. XbStrT end; /* End string stored here.*/
  1328. X
  1329. Xrc = a2smp (str, (limoff < 0) ? NULBSTR : str + limoff, synok, &res, &end);
  1330. Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
  1331. Xif ((0 == rc) && (0 == xrc) &&
  1332. X   ((res.smp_neg != xneg) || (res.smp_el[1] != xhi) || (res.smp_el[0] != xlo)))
  1333. X   PRINTF ("%d: res %c%04X%04X expected %c%04X%04X\n", num,
  1334. X           res.smp_neg ? '-' : '+', res.smp_el[1], res.smp_el[0],
  1335. X           xneg ? '-' : '+', xhi, xlo);
  1336. Xif (xendoff < 0) xendoff = strlen (str);
  1337. Xif ((end - str) != xendoff)
  1338. X   PRINTF ("%d: end %s expected %s\n", num, end, str + xendoff);
  1339. X}
  1340. X
  1341. XPUBLIC int main ()
  1342. X{
  1343. X/*num      str           limoff syn  rc    neg      hi      lo  end */
  1344. Xt(__LINE__,"12",              -1, 0, 0,      0,      0,     12, -1);
  1345. Xt(__LINE__,"0",               -1, 0, 0,      0,      0,      0, -1);
  1346. Xt(__LINE__,"1E6",             -1, 0, 0,      0, 0x000F, 0x4240, -1);
  1347. Xt(__LINE__,"2#1111_1111#",    -1, 0, 0,      0,      0,    255, -1);
  1348. Xt(__LINE__,"16#FF#",          -1, 0, 0,      0,      0,    255, -1);
  1349. Xt(__LINE__,"016#0FF#",        -1, 0, 0,      0,      0,    255, -1);
  1350. Xt(__LINE__,"16#E#E1",         -1, 0, 0,      0,      0,    224, -1);
  1351. Xt(__LINE__,"2#1110_0000#",    -1, 0, 0,      0,      0,    224, -1);
  1352. Xt(__LINE__,NULBSTR,            0, 0, EINVAL, 0,      0,      0,  0);
  1353. Xt(__LINE__,"0",                0, 0, EDOM,   0,      0,      0,  0);
  1354. Xt(__LINE__,"012",              1, 0, 0,      0,      0,      0,  1);
  1355. Xt(__LINE__,"+_012",            4, 0, EDOM,   0,      0,      0,  1);
  1356. Xt(__LINE__,"_0123",            4, 0, EDOM,   0,      0,      0,  0);
  1357. Xt(__LINE__,"-2_147_483_648",  -1, 0, 0,      1, 0x8000, 0x0000, -1);
  1358. Xt(__LINE__," \t2_147_483_647",-1, 1, 0,      0, 0x7FFF, 0xFFFF, -1);
  1359. Xt(__LINE__," \t4_294_967_295",-1, 1, 0,      0, 0xFFFF, 0xFFFF, -1);
  1360. Xt(__LINE__,"1#1111_1111#",    -1, 0, EDOM,   0,      0,      0,  1);
  1361. Xt(__LINE__,"17#1#",           -1, 0, EDOM,   0,      0,      0,  2);
  1362. Xt(__LINE__,"99_e+_2a",        -1, 1, EDOM,   0,      0,      0,  5);
  1363. Xt(__LINE__,"12B",             -1, 1, 0,      0,      0,     12,  2);
  1364. Xt(__LINE__,"16#abcdef#e_0",   -1, 0, EDOM,   0,      0,      0, 11);
  1365. Xt(__LINE__,"16#abcdef#.",     -1, 1, 0,      0, 0x00AB, 0xCDEF, 10);
  1366. Xt(__LINE__,"2#1#E10",         -1, 0, 0,      0,      0,   1024, -1);
  1367. Xt(__LINE__,"-2#1#E10",        -1, 0, 0,      1,      0,   1024, -1);
  1368. X
  1369. Xmfflush (stdout, "Standard Output");
  1370. Xexit (SUCCESS);
  1371. X
  1372. X#ifdef lint
  1373. Xreturn (SUCCESS);
  1374. X#endif
  1375. X}
  1376. X#endif
  1377. END_OF_FILE
  1378. if test 9977 -ne `wc -c <'a2smp.c'`; then
  1379.     echo shar: \"'a2smp.c'\" unpacked with wrong size!
  1380. fi
  1381. # end of 'a2smp.c'
  1382. fi
  1383. if test -f 'new-b.b' -a "${1}" != "-c" ; then 
  1384.   echo shar: Will not clobber existing file \"'new-b.b'\"
  1385. else
  1386. echo shar: Extracting \"'new-b.b'\" \(1456 characters\)
  1387. sed "s/^X//" >'new-b.b' <<'END_OF_FILE'
  1388. X  
  1389. X# new-b.b - create a new Bourne shell source file from a prototype
  1390. X#
  1391. X# $Header: new-b.b,v 1.2 89/09/23 13:49:12 howard Exp $
  1392. X#
  1393. X# Copyright 1989 Howard Lee Gayle
  1394. X# This file is written in the ISO 8859/1 character set.
  1395. X#
  1396. X# This program is free software; you can redistribute it and/or modify
  1397. X# it under the terms of the GNU General Public License version 1,
  1398. X# as published by the Free Software Foundation.
  1399. X#
  1400. X# This program is distributed in the hope that it will be useful,
  1401. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  1402. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1403. X# GNU General Public License for more details.
  1404. X#
  1405. X# You should have received a copy of the GNU General Public License
  1406. X# along with this program; if not, write to the Free Software
  1407. X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1408. X#
  1409. X# Shell variables:
  1410. X# c - '#'
  1411. X# d - '$'
  1412. X# f - steps through files to create
  1413. X# p - file name prefix
  1414. X# u - usage string
  1415. X
  1416. XCMDNAME=new-b
  1417. Xexport CMDNAME
  1418. Xu="Usage: $CMDNAME file..."
  1419. Xif [ $# -eq 0 ]
  1420. Xthen
  1421. X   echo "$u" 1>&2
  1422. X   exit 1
  1423. Xfi
  1424. Xc='#'
  1425. Xd='$'
  1426. Xfor f
  1427. Xdo
  1428. X   p=`basename "$f" .b`
  1429. X   cat << EOF > "$f"
  1430. X$c $f - 
  1431. X$c
  1432. X$c ${d}Header$d
  1433. X$c
  1434. XEOF
  1435. X   if [ "$NEWTEXTPATH" ]
  1436. X   then
  1437. X      cat-path "$NEWTEXTPATH" new.txt | sed -e "s;^;$c ;" >> "$f"
  1438. X   fi
  1439. X   cat << EOF >> "$f"
  1440. X$c Shell variables:
  1441. X$c u - usage string
  1442. X
  1443. XCMDNAME=$p
  1444. Xexport CMDNAME
  1445. Xu="Usage: ${d}CMDNAME"
  1446. Xif [ $d$c -ne . ]
  1447. Xthen
  1448. X   echo "${d}u" 1>&2
  1449. X   exit 1
  1450. Xfi
  1451. XEOF
  1452. Xdone
  1453. END_OF_FILE
  1454. if test 1456 -ne `wc -c <'new-b.b'`; then
  1455.     echo shar: \"'new-b.b'\" unpacked with wrong size!
  1456. fi
  1457. # end of 'new-b.b'
  1458. fi
  1459. echo shar: End of archive 2 \(of 9\).
  1460. cp /dev/null ark2isdone
  1461. MISSING=""
  1462. for I in 1 2 3 4 5 6 7 8 9 ; do
  1463.     if test ! -f ark${I}isdone ; then
  1464.     MISSING="${MISSING} ${I}"
  1465.     fi
  1466. done
  1467. if test "${MISSING}" = "" ; then
  1468.     echo You have unpacked all 9 archives.
  1469.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1470. else
  1471.     echo You still need to unpack the following archives:
  1472.     echo "        " ${MISSING}
  1473. fi
  1474. ##  End of shell archive.
  1475. exit 0
  1476.  
  1477.